﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EasierRdp.Base;
using EasierRdp.Models;
using EasierRdp.Util;

namespace EasierRdp.Forms
{
    partial class GroupDialog : Form
    {
        public bool Existing { get; set; }
        public RdpGroup Group { get; set; }
        public IGroupContainer GroupParent { get; set; }

        public GroupDialog()
        {
            InitializeComponent();
            this.DialogResult = DialogResult.None;
        }

        private void GroupDialog_Load(object sender, EventArgs e)
        {
            if (Group != null)
            {
                TextName.Text = Group.Name;
            }
        }

        private void ButtonOk_Click(object sender, EventArgs e)
        {
            if (Group == null)
            {
                Group = new RdpGroup(TextName.Text);
            }
            else
            {
                Group.Name = TextName.Text;
            }
            if (!Existing)
            {
                if (GroupParent != null)
                {
                    GroupParent.Groups.Add(Group);
                }
            }

            this.DialogResult = DialogResult.OK;
            this.Hide();
            EasierRdpEvents.RebindTreeView();
        }

        private void Button_Cancel_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
    }
}
